package com.valid;

import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.ConstraintViolation;
import javax.validation.Valid;
import javax.validation.Validator;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Set;

@RestController
@Validated
public class BeanController {
    @GetMapping("addString")
    public String addString(@NotBlank String s){
        return s;
    }

    @GetMapping("addUser")
    public String addUSer(UserInfo userInfo) {
        Set<ConstraintViolation> valid = ValidatorUtil.valid(userInfo);
        return valid.size()>0? "fail" : "ok";
    }

    @GetMapping("addUser2")
    public String addUSer2(@Valid UserInfo userInfo, BindingResult result) {
        return "od";
    }
}
